import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vite.dev/config/
export default defineConfig({
  base: './', // 设置基础路径
  publicDir: 'public', // 设置公共资源文件夹
  build: {
    assetsDir: 'assets', // 设置资源输出文件夹
    rollupOptions: {
      output: {
        entryFileNames: 'assets/[name].[hash].js',
        chunkFileNames: 'assets/[name].[hash].js',
        assetFileNames: 'assets/[name].[hash].[ext]',
        cssFileNames: 'css/[name].[hash].[ext]' // 不包含哈希值
      }
    }
  },
  server: {
    https: false, // 是否开启 https
    open: false, // 是否自动在浏览器打开
    port: 3020, // 端口号
    hmr: true, //开启热更新
    host: "0.0.0.0",
    proxy: {
    }
  },
  define: {
    __PUBLIC_PATH__: JSON.stringify(process.env.PUBLIC_URL || '/'),
  },
  plugins: [
    vue(),
    vueJsx(),
    vueDevTools(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@use "@/styles/variables.scss" as *;`,
      },
    }
  },
})
